package com.hualan.sfzyproject.service;

import com.hualan.sfzyproject.domain.Users;
import com.hualan.sfzyproject.mapper.UsersMapper;
import com.hualan.sfzyproject.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.sql.SQLException;

@Service
public class UserService {

    @Autowired
    private UsersMapper usersMapper;

    public int userLogin(String username,String password)
    {
        Users users = usersMapper.selectByUsername(username);
        int i = 0; //用户名/手机号不存在
        if (users != null){ // 用户名/手机号存在
            if (password.equals(users.getUserPassword())){
                i = 1;  // 登录成功
            }else{
                i = -1; //密码错误
            }
        }
        return i;
    }

    //注册
    public int register(Users users){
        return usersMapper.insertSelective(users);
    }

    //修改
    public int updateUser(Users users){
        return usersMapper.updateByPrimaryKeySelective(users);
    }

    //获取用户信息
    public Users getUserInfo(String id){
        return usersMapper.selectByPrimaryKey(id);
    }

}
